package com.gitee.feizns.explore.data_structure.linked_list.singly.deleteNode;

import com.gitee.feizns.explore.data_structure.linked_list.singly.ListNode;

/**
 * @author feizns
 * @since 2020/3/5
 */
public class deleteNode2 {

    private static ListNode create() {
        ListNode ret = new ListNode(-1);
        ret.next = new ListNode(1);
        ret.next.next = new ListNode(2);
        return ret;
    }

    public static void main(String[] args) {
        ListNode node = deleteNode(create(), 1);
        while ( node != null ) {
            System.out.print(node.val);
            node = node.next;
        }
    }

    public static ListNode deleteNode(ListNode head, int val) {
        if ( head != null ) {
            if ( head.val == val )
                return head.next;
            else
                head.next = deleteNode(head.next, val);
        }
        return head;
    }

}
